export const SET_BUSINESS = 'SET_BUSINESS' //商户列表
export const PUSH_BUSINESS = 'PUSH_BUSINESS' //添加商户
export const UPDATE_BUSINESS = 'UPDATE_BUSINESS' //更新商户信息
export const UPDATE_UPDATELIST = 'UPDATE_UPDATELIST' //更新商户是否更新
export const SET_STORE = 'SET_STORE'  //  更新门店信息
export const CLEAR_STORE = 'CLEAR_STORE'  //  清空门店信息
var store = {
    merchantId: '',
    businessProveImg: '',  //  经营场所证明
    merchantName: '',   //  商户名称
    name: '',  //  联系人名称
    categoryCode: '',  //  经营类别
    telephone: '',  //  联系人电话
    province: '',  //  所在省份
    city: '',  //  所在城市
    district: '',  //  所在区县
    detailAddress: '',  //  详细地址
    discount: '', //  折扣
    extraImg: '', //  门店补充图片
    fullAddress: ''// 完整地址
}

export default{
    state:{
        businessList:JSON.parse(window.localStorage.getItem('business')) || {},
        updataList:{type:true},
        store: JSON.parse(window.localStorage.getItem('store')) || store
    },
    mutations: {
        [SET_BUSINESS](state, data) {
            state.businessList = data;
            window.localStorage.setItem('business',JSON.stringify(state.businessList));
        },
        [PUSH_BUSINESS](state, data) {
            state.businessList.content.push(data);
            window.localStorage.setItem('business',JSON.stringify(state.businessList));
        },
        [UPDATE_UPDATELIST](state, data) {
            state.updataList.type = data;
        },
        [UPDATE_BUSINESS](state, data) {
            state.businessList.content.map((v,i)=>{
                if(v.merchantId == data.merchantId){
                    console.log(JSON.stringify(v) + "未合并前")
                    Object.assign(v,data);
                    console.log(JSON.stringify(v)+ "合并后");
                }
            });
            window.localStorage.setItem('business',JSON.stringify(state.businessList));
        },
        [SET_STORE](state, data){
            state.store = Object.assign(state.store, data)
            window.localStorage.setItem('store',JSON.stringify(state.store));
        },
        [CLEAR_STORE](state, data){
            state.store = store
            window.localStorage.setItem('store',JSON.stringify(store));
        },
    },
    actions: {
        [SET_BUSINESS]({commit}, data){
            commit(SET_BUSINESS, data)
        },
        [PUSH_BUSINESS]({commit}, data){
            commit(PUSH_BUSINESS, data)
        },
        [UPDATE_BUSINESS]({commit}, data){
            commit(UPDATE_BUSINESS, data)
        },
        [UPDATE_UPDATELIST]({commit}, data){
            commit(UPDATE_UPDATELIST, data)
        },
        [SET_STORE]({commit}, data){
            commit(SET_STORE, data)
        },
        [CLEAR_STORE]({commit}, data){
            commit(CLEAR_STORE, data)
        },
    }
}